;;; guix-config --- additional software for a custom configuration of gnu-guix
;;; Copyright © 2020 Kolya <kolya.daemon@vfemail.net>
;;;
;;; This file is part of guix-config
;;;
;;; guix-config is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; guix-config is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (kolyad packages virtualization)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system go)
  #:use-module (gnu packages)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gnupg)
  #:use-module (gnu packages golang)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages selinux))

(define-public buildah
  (package
    (name "buildah")
    (version "1.18.0")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                      (url "https://github.com/containers/buildah.git")
                      (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
                (base32 "0kn31y5g7269mjaw5ddfsiaan93s62i8zzxg4xl01dg3dkkadwc4"))))
    (build-system go-build-system)
    (inputs
      `(("btrfs-progs"  ,btrfs-progs)
        ("lvm2"         ,lvm2)
        ("eudev"        ,eudev)
        ("gpgme"        ,gpgme)
        ("libassuan"    ,libassuan)
        ("libgpg-error" ,libgpg-error)
        ("libseccomp"   ,libseccomp)
        ;("libapparmor"  ,libapparmor)
        ("libselinux"   ,libselinux)
        ("glib"         ,glib)))
    (native-inputs
      `(("pkg-config" ,pkg-config)
        ("go-md2man"  ,go-github-com-go-md2man)))
    (arguments
      `(#:import-path "github.com/containers/buildah"
        #:install-source? #f
        #:build-flags '("GIT_COMMIT=none")
        #:tests? #f
        #:phases
        (modify-phases %standard-phases
          (replace 'build
            (lambda* (#:key import-path build-flags #:allow-other-keys)
              (with-directory-excursion (string-append "src/" import-path)
                (apply invoke "make" "bin/buildah" build-flags))))
          (add-after 'build 'build-docs
            (lambda* (#:key import-path outputs build-flags #:allow-other-keys)
              (let ((out (assoc-ref outputs "out")))
                (with-directory-excursion (string-append "src/" import-path)
                  (apply invoke "make" "docs"
                                (string-append "PREFIX=" out)
                                build-flags)))))
          (replace 'check
            (lambda* (#:key import-path build-flags tests? #:allow-other-keys)
              (when tests?
                (with-directory-excursion (string-append "src/" import-path)
                  (apply invoke "make" "test-unit" build-flags)))
                #t))
          (replace 'install
            (lambda* (#:key import-path outputs build-flags #:allow-other-keys)
              (let ((out (assoc-ref outputs "out")))
                (with-directory-excursion (string-append "src/" import-path)
                  (apply invoke "make" "install" "install.completions"
                                (string-append "PREFIX=" out)
                                build-flags))))))))
    (home-page "https://buildah.io")
    (synopsis "build OCI container images")
    (description "The Buildah package provides a command line tool that can be used to
@itemize
@item create a working container, either from scratch or using an image as a starting point
@item create an image, either from a working container or via the instructions in a Dockerfile
@item images can be built in either the OCI image format or the traditional upstream docker image format
@item mount a working container's root filesystem for manipulation
@item unmount a working container's root filesystem
@item use the updated contents of a container's root filesystem as a filesystem layer to create a new image
@item delete a working container or an image
@item rename a local container
@end itemize
To make all features available, you may want to install @code{runc}.")
    (license license:asl2.0)))

;;; vim: set expandtab tabstop=2 shiftwidth=2
;;; end of virtualization.scm
